package com.winit.datasync.service.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.winit.datasync.dao.UpsConfigDao;
import com.winit.datasync.entity.UpsConfig;
import com.winit.datasync.service.UpsConfigService;

@Service("upsConfigService")
public class UpsConfigServiceImpl implements UpsConfigService {

	@Autowired
	private UpsConfigDao upsConfigDao;

	@Transactional
	@Override
	public void batchSave(List<UpsConfig> list, int datasouceType) throws Exception {
		if (null == list || list.size() == 0)
			return;

		if (datasouceType == 2) {
			//mongo单个删除
			for (UpsConfig upsConfig : list) {
				upsConfigDao.delete(upsConfig, datasouceType);
				
			}
		} else if (datasouceType == 1) {
			upsConfigDao.delete(null, datasouceType);
		}

		upsConfigDao.batchInsert(list, datasouceType);

	}

	@Override
	public List<UpsConfig> getByParams(HashMap<String, String> params, int datasouceType)
			throws Exception {
		return upsConfigDao.getByParams(params, datasouceType);
	}

	@Override
	public List<UpsConfig> getAll(int datasouceType) throws Exception {
		return upsConfigDao.getAll(datasouceType);
	}

	@Override
	public void batchMongoSave(List<UpsConfig> newList, List<UpsConfig> existList)
			throws Exception {

		for (UpsConfig upsConfig : newList) {
			upsConfigDao.delete(upsConfig, 2);
		}

		for (UpsConfig upsConfig : existList) {
			upsConfigDao.delete(upsConfig, 2);
		}
		upsConfigDao.batchInsert(existList, 2);
	}

}
